package com.qf.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * projectName:temp_shop
 * author:luo
 * time:2023/3/14 22:10
 * 1自定义自动创建Queue
 * 2自定义自动创建exchange
 * 3自定义自动绑定RKey
 */
@Configuration
public class RabbitMQConfig {
    public static final String EXCHANGE_TOPIC="exchange_2209";
    public static final String QUEUE_1="queue_2209_1";
    public static final String QUEUE_2="queue_2209_2";
    public static final String ROUTINGKEY1="*.orange.*";
    public static final String ROUTINGKEY2="*.*.rabbit";
    public static final String ROUTINGKEY3="lazy.#";

    /**
     * 创建队列1
     */
    @Bean
    public Queue queue1(){
        return QueueBuilder.durable(QUEUE_1).build();
    }
    /**
     * 创建队列2
     */
    @Bean
    public Queue queue2(){
        return QueueBuilder.durable(QUEUE_2).build();
    }
    /**
     * 创建交换机
     */
    @Bean
    public Exchange exchangeTopic(){
        return ExchangeBuilder.topicExchange(EXCHANGE_TOPIC).build();
    }
    /**
     * 绑定 1 exchangeTopic 创建队列1
     */
    @Bean
    public Binding bindingExchangeTopicToQueue1(){
        return BindingBuilder.bind(queue1()).to(exchangeTopic()).with(ROUTINGKEY1).noargs();
    }
    /**
     * 绑定 2 exchangeTopic 创建队列2
     */
    @Bean
    public Binding bindingExchangeTopicToQueue21(){
        return BindingBuilder.bind(queue2()).to(exchangeTopic()).with(ROUTINGKEY2).noargs();
    }
    @Bean
    public Binding bindingExchangeTopicToQueue22(){
        return BindingBuilder.bind(queue2()).to(exchangeTopic()).with(ROUTINGKEY3).noargs();
    }
}
